package at.ac.univie.zsu.aguataplan.domain;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.springframework.format.annotation.DateTimeFormat;

/**
 * @author gerry
 * 
 */
@Entity
public class Player extends Person {

	@Temporal(TemporalType.TIMESTAMP)
	@DateTimeFormat(style = "M-")
	@Column
	private Date activeFrom;

	@Temporal(TemporalType.TIMESTAMP)
	@DateTimeFormat(style = "M-")
	@Column
	private Date activeTo;

	@ManyToMany(cascade = CascadeType.ALL)
	private Set<Functioning> refFunctioning = new HashSet<Functioning>();

	@ManyToMany(cascade = CascadeType.ALL)
	private Set<PlayingPosition> refPlayingPosition = new HashSet<PlayingPosition>();

	@OneToMany(cascade = CascadeType.ALL)
	private Set<Working> refWorking = new HashSet<Working>();

	@OneToMany(cascade = CascadeType.ALL)
	private Set<EventAttributeValuePlayer> refEventAttributeValuePlayer = new HashSet<EventAttributeValuePlayer>();

	// ----------------------------------------------------
	// CONSTRUCTOR
	// ----------------------------------------------------

	public Player() {

	}

	// ----------------------------------------------------
	// METHODS
	// ----------------------------------------------------

	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("ActiveFrom: ").append(getActiveFrom()).append(", ");
		sb.append("ActiveTo: ").append(getActiveTo()).append(", ");
		sb.append("Birthday: ").append(getBirthday()).append(", ");
		sb.append("FirstName: ").append(getFirstName()).append(", ");
		sb.append("Id: ").append(getId()).append(", ");
		sb.append("LastName: ").append(getLastName()).append(", ");
		sb.append("Phone: ").append(getPhone()).append(", ");
		sb.append("RefAttributeValuePlayer: ")
				.append(getRefEventAttributeValuePlayer() == null ? "null" : getRefEventAttributeValuePlayer().size())
				.append(", ");
		sb.append("RefFunctioning: ").append(getRefFunctioning() == null ? "null" : getRefFunctioning().size())
				.append(", ");
		sb.append("RefPersonEMail: ").append(getRefPersonEMail() == null ? "null" : getRefPersonEMail().size())
				.append(", ");
		sb.append("RefPersonWeb: ").append(getRefPersonWeb() == null ? "null" : getRefPersonWeb().size()).append(", ");
		sb.append("RefPlayingPosition: ")
				.append(getRefPlayingPosition() == null ? "null" : getRefPlayingPosition().size()).append(", ");
		sb.append("RefWorking: ").append(getRefWorking() == null ? "null" : getRefWorking().size()).append(", ");
		sb.append("Sex: ").append(getSex()).append(", ");
		sb.append("Version: ").append(getVersion());
		return sb.toString();
	}

	// ----------------------------------------------------
	// GETTER & SETTER
	// ----------------------------------------------------

	public Date getActiveFrom() {
		return activeFrom;
	}

	public void setActiveFrom(Date activeFrom) {
		this.activeFrom = activeFrom;
	}

	public Date getActiveTo() {
		return activeTo;
	}

	public void setActiveTo(Date activeTo) {
		this.activeTo = activeTo;
	}

	public Set<Functioning> getRefFunctioning() {
		return refFunctioning;
	}

	public void setRefFunctioning(Set<Functioning> refFunctioning) {
		this.refFunctioning = refFunctioning;
	}

	public Set<PlayingPosition> getRefPlayingPosition() {
		return refPlayingPosition;
	}

	public void setRefPlayingPosition(Set<PlayingPosition> refPlayingPosition) {
		this.refPlayingPosition = refPlayingPosition;
	}

	public Set<Working> getRefWorking() {
		return refWorking;
	}

	public void setRefWorking(Set<Working> refWorking) {
		this.refWorking = refWorking;
	}

	public Set<EventAttributeValuePlayer> getRefEventAttributeValuePlayer() {
		return refEventAttributeValuePlayer;
	}

	public void setRefEventAttributeValuePlayer(Set<EventAttributeValuePlayer> refEventAttributeValuePlayer) {
		this.refEventAttributeValuePlayer = refEventAttributeValuePlayer;
	}

}
